import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 歌手详情
    singer: {},
    // 歌单详情
    songList: [],
    // 歌手背景图
    singerImg: '',
    // 歌手id
    singerMid: '',
    // 专辑详情
    album: {},
    // 排行榜详情
    rank: {},
    // 歌单类别 歌单/专辑
    type: '',
    // 播放状态
    playing: false,
    // 是否全屏
    fullScreen: false,
    // 播放列表
    playList: [],
    // 顺序播放列表
    sequenceList: [],
    // 播放模式
    mode: 0,
    // 当前播放歌曲索引
    currentIndex: -1,
    // 当前播放歌曲
    currentSong: {},
    // 添加的歌曲列表
    songItem: {},
    // 历史播放
    historyPlay: JSON.parse(localStorage.getItem('historyPlay')) || [],
    // 关注的歌手
    likeSinger: JSON.parse(localStorage.getItem('likeSinger')) || [],
    // // 收藏的专辑
    likeAlbum: JSON.parse(localStorage.getItem('likeAlbum')) || [],
    // 收藏的歌单
    likeSongList: JSON.parse(localStorage.getItem('likeSongList')) || [],
    // 喜欢的歌曲
    likeMusic: JSON.parse(localStorage.getItem('likeMusic')) || [],
    // 收藏的排行榜
    likeRank: JSON.parse(localStorage.getItem('likeRank')) || []
  },
  mutations: {
    // 点击歌手进行切换详情页，传递singer
    setSinger (state, singer) {
      state.singer = singer
    },
    // 点击歌单进行切换详情页，传递songList
    setSongList (state, songList) {
      state.songList = songList
    },
    setSingerImg (state, ImgUrl) {
      state.singerImg = ImgUrl
    },
    setSingerMid (state, Mid) {
      state.singerMid = Mid
    },
    // 点击专辑进行切换详情页，传递album
    setAlbum (state, album) {
      state.album = album
    },
    // 点击排行榜详情
    setRank (state, rank) {
      state.rank = rank
    },
    // 存储歌单类别
    setType (state, type) {
      state.type = type
    },
    // 点击歌曲右边的加号传递歌曲
    setSongItem (state, item) {
      state.songItem = item
    },
    // 设置当前播放歌曲索引
    setCurrentIndex (state, index) {
      state.currentIndex = index
      state.currentSong = state.playList[state.currentIndex]
    },
    // 设置音乐播放状态
    setPlaying (state, playing) {
      state.playing = playing
    },
    // 设置当前播放歌曲
    setCurrentSong (state, currentSong) {
      state.currentSong = currentSong
    },
    // 控制当前播放列表
    setPlayList (state, list) {
      state.playList = JSON.parse(JSON.stringify(list))
      state.currentSong = state.playList[state.currentIndex]
    },
    // 控制顺序播放列表
    setSequenceList (state, list) {
      state.sequenceList = list
    },
    // 设置是否全屏展示
    setFullScreen (state, boolean) {
      state.fullScreen = boolean
    },
    // 设置模式
    setMode (state, mode) {
      state.mode = mode
    },
    // 清除 == 我喜欢 ==
    clearlikeMusic (state) {
      state.likeMusic = []
    },
    // 清空历史播放
    clearHistoryPlay (state) {
      state.historyPlay = []
    }
  },
  actions: {
  },
  modules: {
  }
})
